import qs from '../lib/qyscript.js'
interface ISDKCallbackLinstener {
    initCallback: (cloudsdk: any) => void
}

interface InitOptions {
    sdkCallbackLinstener: ISDKCallbackLinstener
}
export class OnlineSDK {
    private mOptions: InitOptions | null = null
    constructor() {

    }
    public init(options: InitOptions): void {
        this.mOptions = options
        var runTime = new qs.Runtime(window);//创建一个运行时对象
        // 这个文本可以之后放到服务器进行访问
        var that = this;
        var wx = (window as any).wx
        wx.request({
            url: 'http://127.0.0.1:5500/remote.txt',
            success: (res: any) => {
                console.log('远程文本', res.data)
                runTime.regedit(res.data)
                if (that.mOptions != null) {
                    that.mOptions.sdkCallbackLinstener.initCallback(new runTime.g.Test())
                }

            }
        })
    }
}
let gameOnlinesdK: OnlineSDK
if ((window as any).gameOnlinesdK) {
    gameOnlinesdK = (window as any).gameOnlinesdK
} else {
    gameOnlinesdK = new OnlineSDK();
    (window as any).gameOnlinesdK = gameOnlinesdK;
}
export default gameOnlinesdK